import 'package:flutter/services.dart';
import 'package:flutter_native_map/LocationBean.dart';

class FlutterNativeMap {
  static MethodChannel methodChannel =
      const MethodChannel('flutter_native_map');
  static const _eventChannel = EventChannel('flutter_native_map_event');
  static Stream get stream => _eventChannel.receiveBroadcastStream();

  static Future requestPermission() async {
    await methodChannel.invokeMethod("requestPermission");
  }

  static Future<bool> checkPermission() async {
    bool? res = await methodChannel.invokeMethod("checkPermission");
    return res == true;
  }

  static Future<bool> moveCameraTo(double latitude, double longitude) async {
    bool? res = await methodChannel.invokeMethod(
        "moveCameraTo", {"latitude": latitude, "longitude": longitude});
    return res == true;
  }

  static Future drawCircle(
      {required double latitude,
      required double longitude,
      required double radius,
      required Color fillColor,
      required Color strokeColor,
      required double strokeWidth}) async {
    return await methodChannel.invokeMethod("drawCircle", {
      "latitude": latitude,
      "longitude": longitude,
      "radius": radius,
      "fillColor": fillColor.value,
      "strokeColor": strokeColor.value,
      "strokeWidth": strokeWidth,
    });
  }

  static removeCircle(String? circle) async {
    if (circle != null) {
      return await methodChannel
          .invokeMethod("removeCircle", {"circle": circle});
    }
  }

  static Future<LocationBean?> getLocation() async {
    try {
      var res = await methodChannel.invokeMethod("getLocation");
      return LocationBean.fromJson(res.toString());
    } catch (e) {
      return null;
    }
  }

  static Future isGpsOpen() async {
    return await methodChannel.invokeMethod("isGpsOpen");
  }
}
